/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.xs_notice.service;

import java.util.Date;
import java.util.List;

import com.jeeplus.modules.xs_notice_user.entity.XsNoticeUser;
import com.jeeplus.modules.xs_notice_user.mapper.XsNoticeUserMapper;
import com.jeeplus.modules.xs_user.entity.XsUser;
import com.jeeplus.modules.xs_user.mapper.XsUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.xs_notice.entity.XsNotice;
import com.jeeplus.modules.xs_notice.mapper.XsNoticeMapper;

/**
 * 系统通知信息Service
 * @author 天竹子
 * @version 2021-07-15
 */
@Service
@Transactional(readOnly = true)
public class XsNoticeService extends CrudService<XsNoticeMapper, XsNotice> {
	@Autowired
	XsUserMapper xsUserMapper;
	@Autowired
	XsNoticeUserMapper xsNoticeUserMapper;

	public XsNotice get(String id) {
		return super.get(id);
	}
	
	public List<XsNotice> findList(XsNotice xsNotice) {
		return super.findList(xsNotice);
	}
	
	public Page<XsNotice> findPage(Page<XsNotice> page, XsNotice xsNotice) {
		return super.findPage(page, xsNotice);
	}
	
	@Transactional(readOnly = false)
	public void save(XsNotice xsNotice) {
		xsNotice.setCreateDate(new Date());
		super.save(xsNotice);
		XsNoticeUser xsNoticeUser = new XsNoticeUser();
		xsNoticeUser.setNoticeId(xsNotice.getId());
		xsNoticeUser.setIsRead(2);
		xsNoticeUser.setCreateDate(new Date());
		List<XsUser> list = xsUserMapper.findList(null);
		for(XsUser xsUser : list) {
			xsNoticeUser.setUser(xsUser);
			xsNoticeUserMapper.insert(xsNoticeUser);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(XsNotice xsNotice) {
		super.delete(xsNotice);
	}
	
}